<html>
<head><meta charset="utf-8"><title>Compiler generates loop that unnecessarily repeats... #80989 · t-compiler/wg-llvm · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/187780-t-compiler/wg-llvm/index.html">t-compiler/wg-llvm</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/187780-t-compiler/wg-llvm/topic/Compiler.20generates.20loop.20that.20unnecessarily.20repeats.2E.2E.2E.20.2380989.html">Compiler generates loop that unnecessarily repeats... #80989</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="222713177"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187780-t-compiler/wg-llvm/topic/Compiler%20generates%20loop%20that%20unnecessarily%20repeats...%20%2380989/near/222713177" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nagisa <a href="https://rust-lang.github.io/zulip_archive/stream/187780-t-compiler/wg-llvm/topic/Compiler.20generates.20loop.20that.20unnecessarily.20repeats.2E.2E.2E.20.2380989.html#222713177">(Jan 14 2021 at 13:01)</a>:</h4>
<p>This is an interesting failure mode. At LLVM-IR the comparison is properly outside of the loop, but I imagine DAG does not realize/preserve this for some reason?</p>



<a name="222791706"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187780-t-compiler/wg-llvm/topic/Compiler%20generates%20loop%20that%20unnecessarily%20repeats...%20%2380989/near/222791706" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Nikita Popov <a href="https://rust-lang.github.io/zulip_archive/stream/187780-t-compiler/wg-llvm/topic/Compiler.20generates.20loop.20that.20unnecessarily.20repeats.2E.2E.2E.20.2380989.html#222791706">(Jan 14 2021 at 22:08)</a>:</h4>
<p>I'd guess that it prefers place icmps next to branches, as most architectures combine both in some way.</p>



<a name="222791769"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187780-t-compiler/wg-llvm/topic/Compiler%20generates%20loop%20that%20unnecessarily%20repeats...%20%2380989/near/222791769" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Nikita Popov <a href="https://rust-lang.github.io/zulip_archive/stream/187780-t-compiler/wg-llvm/topic/Compiler.20generates.20loop.20that.20unnecessarily.20repeats.2E.2E.2E.20.2380989.html#222791769">(Jan 14 2021 at 22:09)</a>:</h4>
<p>There's probably a phase ordering problem here, as LoopUnswitch should be moving that branch out of the loop. Adding a -C passes=loop-unswitch does work.</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>